<template>
  <DeviceBrandTypeTree @changeWorkshop="changeWorkshop">
    <template slot="right-content">
      <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24"> </a-row>
          </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-button type="primary" icon="download" @click="handleExportXls('设备管理')">导出</a-button>
          <a-upload
            name="file"
            :showUploadList="false"
            :multiple="false"
            :headers="tokenHeader"
            :action="importExcelUrl"
            @change="handleImportExcel"
          >
            <a-button type="primary" icon="import">导入</a-button>
          </a-upload>
          <!-- 高级查询区域 -->
          <j-super-query
            :fieldList="superFieldList"
            ref="superQueryModal"
            @handleSuperQuery="handleSuperQuery"
          ></j-super-query>
          <a-dropdown v-if="selectedRowKeys.length > 0">
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
            </a-menu>
            <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down"/></a-button>
          </a-dropdown>
        </div>

        <!-- table区域-begin -->
        <div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
            <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
            >项
            <a style="margin-left: 24px" @click="onClearSelected">清空</a>
          </div>

          <a-table
            ref="table"
            size="middle"
            :scroll="{ x: true }"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            class="j-table-force-nowrap1"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width:80px;font-size: 12px;font-style: italic;"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleDeviceQrcode(record)">
                <svg
                  t="1717646069947"
                  class="icon"
                  viewBox="0 0 1024 1024"
                  version="1.1"
                  xmlns="http://www.w3.org/2000/svg"
                  p-id="1476"
                  width="20"
                  height="20"
                  style="position: relative;top:5px;"
                  title="设备二维码"
                >
                  <path
                    d="M224 416.096V224l192-0.096 0.096 192.096L224 416.096zM416.096 160H223.904A64 64 0 0 0 160 223.904v192.192A64 64 0 0 0 223.904 480h192.192A64 64 0 0 0 480 416.096V223.904A64 64 0 0 0 416.096 160zM224 800.096V608l192-0.096 0.096 192.096L224 800.096zM416.096 544H223.904A64 64 0 0 0 160 607.904v192.192A64 64 0 0 0 223.904 864h192.192A64 64 0 0 0 480 800.096v-192.192A64 64 0 0 0 416.096 544zM608 416.096V224l192-0.096 0.096 192.096-192.096 0.096zM800.096 160h-192.192A64 64 0 0 0 544 223.904v192.192A64 64 0 0 0 607.904 480h192.192A64 64 0 0 0 864 416.096V223.904A64 64 0 0 0 800.096 160zM704 608a32 32 0 0 0-32 32v192a32 32 0 0 0 64 0v-192a32 32 0 0 0-32-32M576 608a32 32 0 0 0-32 32v192a32 32 0 0 0 64 0v-192a32 32 0 0 0-32-32M832 544a32 32 0 0 0-32 32v256a32 32 0 0 0 64 0v-256a32 32 0 0 0-32-32"
                    fill="#0a7dbf"
                    p-id="1477"
                  ></path>
                </svg>

              </a>
              <a-divider type="vertical" />
              <a @click="handleEdit(record)">编辑</a>

              <a-divider type="vertical" />
              <a @click="handleDeviceDetail(record)">详情</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
              <!-- <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
            </span>
          </a-table>
        </div>

        <ene-device-modal ref="modalForm" @ok="modalFormOk"></ene-device-modal>
        <ene-device-detail-modal ref="modalDetail"></ene-device-detail-modal>
        <ene-device-qrcode-modal ref="modalDetailQrcode"></ene-device-qrcode-modal>
      </a-card>
    </template>
  </DeviceBrandTypeTree>
</template>

<script>
import DeviceBrandTypeTree from '@/components/energy/DeviceBrandTypeTree'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import EneDeviceModal from './modules/EneDeviceModal'
import EneDeviceDetailModal from './modules/EneDeviceDetailModal'
import EneDeviceQrcodeModal from './modules/EneDeviceQrcodeModal'

export default {
  name: 'EneDeviceList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    EneDeviceModal,
    EneDeviceDetailModal,
    DeviceBrandTypeTree,
    EneDeviceQrcodeModal
  },
  data() {
    return {
      description: '设备管理管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '设备名称',
          align: 'center',
          dataIndex: 'deviceName'
        },
        {
          title: '设备ID',
          align: 'center',
          dataIndex: 'deviceId'
        },
        {
          title: '产品',
          align: 'center',
          dataIndex: 'deviceProductId_dictText'
        },
        {
          title: '型号',
          align: 'center',
          dataIndex: 'deviceTypeId'
        },
        {
          title: '品牌',
          align: 'center',
          dataIndex: 'deviceBrandId_dictText'
        },
        {
          title: '用能单位',
          align: 'center',
          dataIndex: 'deviceWorkshopId_dictText'
        },
        // {
        //   title:'采购部门',
        //   align:"center",
        //   dataIndex: 'devicePurchaseDeptId_dictText'
        // },
        // {
        //   title:'采购人',
        //   align:"center",
        //   dataIndex: 'devicePurchaseUserId_dictText'
        // },
        // {
        //   title:'采购日期',
        //   align:"center",
        //   dataIndex: 'devicePurchaseDate'
        // },
        {
          title: '使用部门',
          align: 'center',
          dataIndex: 'deviceUseDeptId_dictText'
        },
        {
          title: '使用负责人',
          align: 'center',
          dataIndex: 'deviceUseUserId_dictText'
        },
        {
          title: '在线状态',
          align: 'center',
          dataIndex: 'deviceStatus_dictText'
        },
        {
          title: '使用状态',
          align: 'center',
          dataIndex: 'deviceUseStatus_dictText'
        },
        // {
        //   title:'设备位置',
        //   align:"center",
        //   dataIndex: 'devicePosition'
        // },
        // {
        //   title:'备注',
        //   align:"center",
        //   dataIndex: 'deviceRemarks'
        // },
        // {
        //   title:'设备图片',
        //   align:"center",
        //   dataIndex: 'deviceImages',
        //   scopedSlots: {customRender: 'imgSlot'}
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/device/eneDevice/list',
        delete: '/device/eneDevice/delete',
        deleteBatch: '/device/eneDevice/deleteBatch',
        exportXlsUrl: '/device/eneDevice/exportXls',
        importExcelUrl: 'device/eneDevice/importExcel'
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()
    this.loadData()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'deviceName', text: '设备名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'deviceId', text: '设备ID', dictCode: '' })
      fieldList.push({
        type: 'sel_search',
        value: 'deviceProductId',
        text: '产品',
        dictTable: 'ene_device_product',
        dictText: 'device_product_name',
        dictCode: 'id'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'deviceTypeId',
        text: '型号',
        dictTable: 'ene_device_type',
        dictText: 'device_type_name',
        dictCode: 'id'
      })
      fieldList.push({
        type: 'string',
        value: 'deviceBrandId',
        text: '品牌',
        dictTable: 'ene_device_brand',
        dictText: 'brand_name',
        dictCode: 'id'
      })
      fieldList.push({ type: 'int', value: 'deviceStatus', text: '在线状态', dictCode: '' })
      fieldList.push({ type: 'sel_depart', value: 'devicePurchaseDeptId', text: '采购部门' })
      fieldList.push({ type: 'sel_user', value: 'devicePurchaseUserId', text: '采购人' })
      fieldList.push({ type: 'datetime', value: 'devicePurchaseDate', text: '采购日期' })
      fieldList.push({ type: 'sel_depart', value: 'deviceUseDeptId', text: '使用部门' })
      fieldList.push({ type: 'sel_user', value: 'deviceUseUserId', text: '使用负责人' })
      fieldList.push({ type: 'string', value: 'devicePosition', text: '设备位置', dictCode: '' })
      fieldList.push({ type: 'string', value: 'deviceRemarks', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'deviceImages', text: '设备图片', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleDeviceDetail(record) {
      this.$refs.modalDetail.detail(record)
    },
    handleDeviceQrcode(record) {
      this.$refs.modalDetailQrcode.detail(record)
    },
    changeWorkshop(...e) {
      this.checkedNodesIds = e
      this.loadData()
    },
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';

/deep/ .ant-modal {
  width: 1200px !important;
}

/deep/ .remarks .ant-form-item-label,
/deep/ .images .ant-form-item-label {
  width: 80px;
}
</style>
